<?php require ('setcookie.html'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html lang="de">
<head>
    <title>Lingomoto - Freischaltung Registrierung - Sprachen lernen</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="Lingomoto - Freischaltung Registrierung - Sprachen lernen" />
    <meta name="language" content="de" />
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
</head>

<body >

<?php
$_SESSION['logini'] = isset($_SESSION['logini']) ? $_SESSION['logini'] : false;
// read configuration
require ('konfiguration.html');
// read user-data
require ('nutzer.html');
// read header
$link = "rg-frei.html";
$langen = 'rg-free.html';
$langes = 'rg-libre.html';
$langru = 'rg-free.html';
require ('kopf.html');
// <!-- horizontal column -->
echo '<div>';
require ('horizontal.html');
echo '</div>';
// <!-- Left Column -->
echo '<div id="left_col">';
require ('vertikal.html');
echo '</div>';

// <!-- Content -->
echo '<div id="content">';
echo '<div id="block5">';

// request for login
if ($_SESSION['logini']== false and $error <> '') {
    require_once ('loginformular.html'); 
}
// if new password, request for change of password
elseif ( $newpass == 1 )
{
    $passwo = isset($_REQUEST['passwo']) ? $_REQUEST['passwo'] : '1';
    $passwo1 = isset($_REQUEST['passwo1']) ? $_REQUEST['passwo1'] : '1';
    $passwo2 = isset($_REQUEST['passwo2']) ? $_REQUEST['passwo2'] : '1';
    $ok='';
    require_once ('neues-passwort.html');
}
else
{
$id = isset($_GET['id']) ? $_GET['id'] : "";
$email = isset($_GET['mail']) ? $_GET['mail'] : "";

if ($id <>"" and $email <>"") {
$sql = "SELECT * FROM customerdata where email ='". $email . "' and controlno =". $id ." ";

// DB Query
$db_sel1 = mysql_query( $sql );
if ( ! $db_sel1 )
    { die('Error query: ' . mysql_error()); }
else
    { 
/*    while ($row = mysql_fetch_array( $db_sel1, MYSQL_ASSOC)) {
        $newsletter = $row['newsletter']; 
        $registered = $row['registered']; }  */
    
    $num_rows = mysql_num_rows($db_sel1);
    if ( $num_rows <> 0 ) { update(); }
    else {
        echo "<div class='message'>Email ";
        echo $email;
        echo " noch nicht registriert. Bitte neu registrieren!</div>"; 
        }
    }
}
else
{
    echo "<h2>Du wurdest freigeschaltet</h2>";  
    echo '<br />';
    echo '<div class="content_frame">Du kannst nun alle Funktionen von Lingomoto nutzen:<br />';
    echo '<div class="buttonright"><a href="vokabeltrainer.html"><img src="bilder/buttons/weiter.gif" alt="Weiter" title=" Weiter " /></a></div>';
    echo '</div>';
}}
// ----------------------- Functions --------------------------------------------------------------------------------------------

function update () {

    global $email,$id,$newsletter,$registered;

    $sql1  = "update customerdata set registered = 1 where email ='". $email . "' ";
    $sql1 .= "and controlno =". $id . " "; 

    $sql2  = "select customerid from customerdata where email ='". $email . "' "; 

    // DB Query
    $db_upd = mysql_query( $sql1 );
    if ( ! $db_upd ) 
        { die('Error query: ' . mysql_error()); }
    else
        { 
        // set settings
        $db_sel = mysql_query( $sql2 );
        if ( ! $db_sel ) { die('Error query: ' . mysql_error()); }
        else 
            { while ($row = mysql_fetch_array( $db_sel, MYSQL_ASSOC)) {
                $customerid = $row['customerid']; } 

                $sql4 = "SELECT * FROM settings where customerid =". $customerid;
                $db_sel4 = mysql_query( $sql4 );
                if ( ! $db_sel4 ) { die('Error query: ' . mysql_error()); }
                $num_rows4 = mysql_num_rows($db_sel4);
                if ( $num_rows4 == 0 )
                {
                    $sql3  = "insert into settings set customerid = ". $customerid ." , maxqty = 100 ";
                    $db_ins = mysql_query( $sql3 );
                    if ( ! $db_ins ) { die('Error query: ' . mysql_error()); }
                }    
                echo "<h2>Du wurdest freigeschaltet</h2>"; } 
        }
}

echo '</div>';
echo '</div>';
echo '<div id="adverts">';
echo '<div id="adbox"></div>';
echo '</div>';
require ('fuss.html');
?>

</body>
</html>